package jiubeirobot.com.robotshop.ui.activity;

import jiubeirobot.com.robotshop.base.Activitys;
import jiubeirobot.com.robotshop.base.BaseActivity;
import jiubeirobot.com.robotshop.base.BaseBean;
import jiubeirobot.com.robotshop.base.BaseData;
import jiubeirobot.com.robotshop.bean.ObjBean;
import jiubeirobot.com.robotshop.bean.ShopIDByBarcode;
import jiubeirobot.com.robotshop.data.constans.Constants;
import jiubeirobot.com.robotshop.data.net.APIManager;
import jiubeirobot.com.robotshop.data.net.Flags;
import jiubeirobot.com.robotshop.utils.DataUtil;
import jiubeirobot.com.robotshop.utils.L;

/**
 * @author TheJoker丶豪
 * @date 创建时间:2017/8/23
 * 监测扫码枪扫描数据返回的接收的activity
 */

public class ScanResultActivity extends BaseActivity {
    String barcode;//扫描的商品的码的值

    @Override
    public int pageLayout() {
        return -1;
    }

    @Override
    public void initTitle() {

    }

    @Override
    public void initView() {
        barcode = getIntent().getStringExtra(Constants.INTENT_SHOP_BARCODE);
        L.i(barcode);
        APIManager.getInstance().getShopIDByBarcode(this, barcode.toString().trim(), DataUtil.getInstance().getMobileNumber(ScanResultActivity.this));
    }

    @Override
    public void onSuccess(BaseBean bean, int flag) {
        switch (flag) {
            case Flags.FLAG_SHOPID_BY_BARCODE:
                BaseBean<ObjBean<ShopIDByBarcode>> shopcodebean = bean;
                String id = shopcodebean.getData().getObj().getGoods_id();
                if (id != null) {
                    Activitys.toShopListByType(ScanResultActivity.this, id);
                }
                break;
            default:
                break;
        }
        dismissHUD();
    }

    @Override
    public void onError(String error, int flag) {
        super.onError(error, flag);
        finish();
    }
}